<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/scripts/fileuploader/fileuploader.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/scripts/fileuploader/fileuploader.css');
?>
<br/>
<div class="form">

    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'categorys-form',
        'enableAjaxValidation' => true,
            ));
    ?>

    <?php echo $form->errorSummary($model); ?>
    <fieldset>
        <legend>基本设置</legend>

        <div class="row" style="float:left;">
            <?php echo $form->labelEx($model, 'category_parent'); ?>
            <?php echo $form->dropDownList($model, 'category_parent', array('0' => '一级分类') + CHtml::listData(Categorys::model()->findAll('category_parent=0'), 'id', 'category_name')); ?>
            <?php echo $form->error($model, 'category_parent'); ?>
        </div>

        <div class="row" style="float:left;margin-left: 20px;">
            <?php echo $form->labelEx($model, 'category_model'); ?>
            <?php echo $form->dropDownList($model, 'category_model', $model->category_model_array); ?>
            <?php echo $form->error($model, 'category_model'); ?>
        </div>

        <div class="row" style="float:left;margin-left: 20px;">
            <?php echo $form->labelEx($model, 'category_type'); ?>
            <?php echo $form->dropDownList($model, 'category_type', $model->category_type_array); ?>
            <?php echo $form->error($model, 'category_type'); ?>
        </div>

        <div class="row" style="float:left;margin-left: 20px;">
            <?php echo $form->labelEx($model, 'category_status'); ?>
            <?php echo $form->dropDownList($model, 'category_status', array(Categorys::STATUS_ALLOW => '启用', Categorys::STATUS_DENY => '禁用')); ?>
            <?php echo $form->error($model, 'category_status'); ?>
        </div>

        <div class="row" style="float:left;margin-left: 20px;">
            <?php echo $form->labelEx($model, 'category_ismenu'); ?>
            <?php echo $form->dropDownList($model, 'category_ismenu', array(Categorys::ISMENU_YES => '是', Categorys::ISMENU_NO => '否')); ?>
            <?php echo $form->error($model, 'category_ismenu'); ?>
        </div>

        <div class="row" style="float:left;margin-left: 20px;">
            <?php echo $form->labelEx($model, 'category_order'); ?>
            <?php echo $form->textField($model, 'category_order'); ?>
            <?php echo $form->error($model, 'category_order'); ?>
        </div>

        <div class="clear"></div>

    </fieldset>

    <fieldset>
        <legend>内容设置</legend>
        <div class="row">
            <?php echo $form->labelEx($model, 'category_image'); ?>
            <?php echo $form->textField($model, 'category_image', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'category_image'); ?>
            <div id="upload-thum">
                <noscript>          
                <p>Please enable JavaScript to use file uploader.</p>
                </noscript>   
            </div>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'category_name'); ?>
            <?php echo $form->textField($model, 'category_name', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'category_name'); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'category_alias'); ?>
            <?php echo $form->textField($model, 'category_alias', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'category_alias'); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'category_intro'); ?>
            <?php echo $form->textArea($model, 'category_intro', array('rows' => 5, 'cols' => 95)); ?>
            <?php echo $form->error($model, 'category_intro'); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'category_content'); ?>
            <?php echo $form->textArea($model, 'category_content', array('rows' => 20, 'cols' => 95)); ?>
            <?php
            $this->widget('ext.kindeditor.KindEditor', array(
                'model' => $model,
                'attribute' => 'category_content',
                    )
            );
            ?>
            <?php echo $form->error($model, 'category_content'); ?>

        </div>
    </fieldset>

    <fieldset>
        <legend>SEO设置</legend>
        <div class="row">
            <?php echo $form->labelEx($model, 'seo_title'); ?>
            <?php echo $form->textField($model, 'seo_title', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'seo_title'); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'seo_keywords'); ?>
            <?php echo $form->textField($model, 'seo_keywords', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'seo_keywords'); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'seo_description'); ?>
            <?php echo $form->textArea($model, 'seo_description', array('rows' => 6, 'cols' => 90)); ?>
            <?php echo $form->error($model, 'seo_description'); ?>
        </div>
    </fieldset>

    <fieldset class="tblFooters">
        <div class="row buttons">
            <?php echo CHtml::submitButton($model->isNewRecord ? ' 添 加 ' : ' 保 存 '); ?>
        </div>
    </fieldset>


    <?php $this->endWidget(); ?>

</div><!-- form -->

<script>
    //file upload
    var upimg='';
    var img_ext = "|jpg|jpeg|png|gif|bmp|";
    function createUploader(elementObj, setValueObj){//   elementObj: DIV, setValueObj: Will set value INPUT    
        var uploader = new qq.FileUploader({
            element: elementObj,
            action: '<?php echo Yii::app()->baseUrl; ?>/fileUpload.php',
            debug: false,
            showMessage: function(message){ alert(message); },
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp'],
            onProgress: function(id, fileName, loaded, total){
                //location.reload();
            },
            onComplete:function(id, fileName, responseJSON){
                if(responseJSON.success){
                    var dot_index = responseJSON.url.lastIndexOf('.');
                    var ext = responseJSON.url.substring(dot_index+1);
                    if(img_ext.indexOf(ext)>0){
                        //setValueObj.value=responseJSON.url;
                        setValueObj.val(responseJSON.url);
                    }
                }
            }
        });
        uploader.setParams({dir:"category"});
    }
    $(window).load(function(){
        createUploader(document.getElementById("upload-thum"), $("#Categorys_category_image"));
    });
</script>